home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
3_0
/
SPIRO_SO
/
ABOUT.C
next >
Wrap
Text File
|
1989-06-17
|
7KB
|
418 lines
/*
(c) copyright 1988 Symantec Corporation. For use with THINK's Lightspeed C only.
You may incorporate these routines in any of your programs, for commercial distribution
or otherwise, but you may not charge for the specific use of this code. Symantec
Corporation makes no warranty regarding the fitness of this software for any particular
purpose.
about.c -- a generic "about" box for any Macintosh program written in Lightspeed C.
To use this, just define the strings below, add the file to your project, and
call "aboutcommand" from your menu handling procedure.
Not too big, kind of sexy, and certainly better than nothing!
Thanks to Galen Babcock and Apple Computer...
First upload to LVTFORUM on Compuserve by Dave Winer: 1/24/88
*/
#define line1 "\pJohn's Fabulous Spiro-Program"
#define line2 "\pWritten by John Nalezny"
#define line3 "\pCompuserve 72137,1212"
#define line4 "\pVersion 1.0"
#define line5 "\pJune 17 1989"
#define line6 "\pCatch the ~ !"
#include "MacTypes.h"
#include "QuickDraw.h"
#include "EventMgr.h"
#include "DialogMgr.h"
#include "FontMgr.h"
#include "standard.h"
#define zoomfixer 65536L
#define zoomsteps 16
Fixed zoomfract;
#define ctportstackelements 10 /*we can remember ports up to 10 levels deep*/
#define maxportstack 9 /*this is the highest valid index in the port stack*/
int topportstack;
GrafPtr portstack [ctportstackelements];
#if 0
initmacintosh () {
/*
the magic stuff that every macintosh application needs to do
before doing anything else.
*/
register int i;
MaxApplZone ();
for (i = 1; i < 11; i++)
MoreMasters ();
InitGraf (&thePort);
InitFonts ();
FlushEvents (everyEvent, 0);
InitWindows ();
InitMenus ();
TEInit ();
InitDialogs (nil);
InitCursor();
} /*initmacintosh*/
#endif
pushport (p) GrafPtr p; {
if (topportstack < maxportstack) /*room left to push something*/
portstack [topportstack++] = thePort;
if (p != nil)
SetPort (p);
} /*pushport*/
popport () {
if (topportstack > 0) /*there's something in the stack to pop*/
SetPort (portstack [--topportstack]);
} /*popport*/
localtoglobalrect (r) Rect *r; {
Point p1, p2;
p1 = topLeft (*r);
p2 = botRight (*r);
LocalToGlobal (&p1);
LocalToGlobal (&p2);
Pt2Rect (p1, p2 ,r);
} /*localtoglobalrect*/
int blend (i1, i2) int i1, i2; {
Fixed smallFix,bigFix,tempFix;
smallFix = zoomfixer * i1;
bigFix = zoomfixer * i2;
tempFix = FixMul(zoomfract,bigFix)+FixMul(zoomfixer-zoomfract,smallFix);
return(FixRound(tempFix));
} /*blend*/
zoomrect (smallrect, bigrect, zoomup)
Rect *smallrect,*bigrect;
boolean zoomup;
{
Fixed factor;
Rect rect1,rect2,rect3,rect4;
GrafPtr savePort,deskPort;
int i;
GetPort (&savePort);
OpenPort (deskPort = (GrafPtr) NewPtr (sizeof (GrafPort)));
InitPort (deskPort);
SetPort (deskPort);
PenPat (gray);
PenMode (notPatXor);
if (zoomup) {
rect1 = *smallrect;
factor = FixRatio(6,5);
zoomfract = FixRatio(541,10000);
}
else {
rect1 = *bigrect;
factor = FixRatio(5,6);
zoomfract = zoomfixer;
}
rect2 = rect1;
rect3 = rect1;
FrameRect (&rect1);
for (i = 1; i<= zoomsteps; i++) {
rect4.left = blend (smallrect->left, bigrect->left);
rect4.right = blend (smallrect->right, bigrect->right);
rect4.top = blend (smallrect->top, bigrect->top);
rect4.bottom = blend (smallrect->bottom, bigrect->bottom);
FrameRect (&rect4);
FrameRect (&rect1);
rect1 = rect2;
rect2 = rect3;
rect3 = rect4;
zoomfract = FixMul (zoomfract,factor);
} /*for*/
FrameRect (&rect1);
FrameRect (&rect2);
FrameRect (&rect3);
ClosePort (deskPort);
DisposPtr ((Ptr)deskPort);
PenNormal ();
SetPort (savePort);
} /*zoomrect*/
zoomport (w, flup) WindowPtr w; boolean flup; {
/*
Zooms the window referenced by "w" either from an inivisible
state to a visible state, or vice versa. Pass true in the "flup"
boolean parameter to zoom a window to open, an false to zoom
it close. The WindowPtr must have already been created elsewhere,
and zooming the window invisible only hides the window, it does
not destroy the WindowPtr data.
*/
Rect r1, r2, r3;
SetPort (w);
SetRect (&r1, 0, 20, 0, 20);
r3 = (*w).portRect;
r2 = r3;
InsetRect (&r2, (r3.right - r3.left + 20) / 2, (r3.bottom - r3.top + 20) / 2);
localtoglobalrect (&r2);
localtoglobalrect (&r3);
if (flup) {
zoomrect (&r1, &r2, true);
zoomrect (&r2, &r3, true);
ShowWindow (w);
SetPort (w);
}
else {
HideWindow (w);
zoomrect (&r2, &r3, false);
zoomrect (&r1, &r2, false);
}
} /*zoomport*/
positionaboutwindow (pdialog, rscreen) WindowPtr pdialog; Rect rscreen; {
int h, v;
Rect rdialog;
rdialog = (*pdialog).portRect;
h = rscreen.left + (((rscreen.right - rscreen.left) - (rdialog.right - rdialog.left)) / 2);
v = rscreen.top + (((rscreen.bottom - rscreen.top) - (rdialog.bottom - rdialog.top)) / 3);
MoveWindow (pdialog, h, v, false);
} /*positionaboutwindow*/
pascalcopy (bssource, bsdest) bigstring *bssource, *bsdest; {
/*
create a copy of bssource in bsdest.
*/
register int i, len;
for (i = 0; i <= (len = (*bssource) [0]);)
(*bsdest) [i] = (*bssource) [i++];
} /*pascalcopy*/
#define doline(x)\
\
pascalcopy ((ptrstring) x, &bs); \
\
MoveTo (r.left + (r.right - r.left - StringWidth (bs)) / 2, linev); \
\
DrawString (bs); \
\
linev += lineinc;
void drawabout (w) WindowPtr w; {
bigstring bs;
Rect r;
int linev = 24;
int lineinc = 14;
int index;
Rect rtext;
r = (*w).portRect;
InsetRect (&r, 4, 4);
TextFont (systemFont);
TextSize (12);
doline (line1);
TextFont (geneva);
TextSize (9);
doline (line2);
doline ("\p");
doline (line3);
doline (line4);
pascalcopy ((ptrstring) line5, &bs);
MoveTo (r.left + 4, r.bottom - 6);
DrawString (bs);
pascalcopy ((ptrstring) line6, &bs);
MoveTo (r.right - StringWidth (bs) - 4, r.bottom - 6);
DrawString (bs);
} /*drawabout*/
void aboutcommand () {
GrafPtr eventport;
Rect r;
EventRecord ev;
WindowPtr w;
boolean flbitmap;
InitCursor ();
SetRect (&r, 0, 0, 340, 120);
pushport (w = NewWindow (nil, &r, "\p", false, altDBoxProc, -1L, false, 0));
positionaboutwindow ((DialogPtr) w, screenBits.bounds);
zoomport (w, true);
drawabout (w);
while (true){
if (!GetNextEvent (everyEvent, &ev))
continue;
switch (ev.what) {
case keyDown:
case autoKey:
case mouseDown:
goto exit;
case updateEvt: /*handle updates, he might be using Pyro!*/
if ((WindowPtr) (ev.message) == w) {
pushport (w);
BeginUpdate (w);
drawabout (w);
EndUpdate (w);
popport ();
}
break;
} /*switch*/
} /*while*/
exit:
HideWindow (w);
zoomport (w, false);
DisposeWindow (w);
popport ();
FlushEvents (mDownMask + keyDownMask, 0);
} /*aboutcommand*/